package gamagora.game.entity
{
	import Box2D.Collision.Shapes.b2CircleShape;

	public class OSCircle extends OSPhysicEntity
	{
		protected var _radius:Number;
		
		public function OSCircle(type:uint, X:Number=0, Y:Number=0, radius:Number = 0, SimpleGraphic:Class = null)
		{
			super(type, X, Y, SimpleGraphic);
			_radius = radius;
			
			width = _radius * 2;
			height = _radius * 2;
			_physicWidth = _radius * 2;
			_physicHeight = _radius * 2;
			
			//Préparation de la physique
			var circleShape:b2CircleShape = new b2CircleShape(_radius / RATIO);
			_fixDef.shape = circleShape;
			_bodyDef.position.Set((x + _radius) / RATIO, (y + (_radius / 2)) / RATIO);
		}
		
		public override function update():void
		{
			super.update();
			x = (_body.GetPosition().x * RATIO) - _radius;
			y = (_body.GetPosition().y * RATIO) - _radius;
			angle = _body.GetAngle() * (180 / Math.PI);
		}
		
		public override function setStartX(decalX:Number):void
		{
			x += decalX;
			_startX += decalX;
			_bodyDef.position.Set((x + _radius) / RATIO, (y + (_radius / 2)) / RATIO);
			for(var i:uint=0;i<_nbEntities;i++)
			{
				_entities[i].setStartX(decalX);
			}
		}
	}
}
